import 'package:flutter/material.dart';
import 'package:sharing/model/origin_article.dart';
import 'package:sharing/utils/whole_apis.dart';
import 'package:dio/dio.dart';
import 'package:markdown/markdown.dart' as md;

import 'package:flutter_html_view/flutter_html_view.dart';

class OriginArticlePage extends StatefulWidget {
  OriginArticlePage({@required this.article}) : assert(article != null);

  final OriginArticle article;

  @override
  _ArticleState createState() => _ArticleState();
}

class _ArticleState extends State<OriginArticlePage> {
  bool isLoad = true;
  String _markdownData = "";

  @override
  void initState() {
    super.initState();

    _downloadMdFile();
  }

  void _downloadMdFile()async{
    Response response =await new Dio().get(WholeApis.hostName+'/'+widget.article.link);
    if (response.statusCode == 200){
      String _data = response.data;
      setState(() {
        _markdownData = _data;
        isLoad = false;
      });
    }
  }
  @override
  Widget build(BuildContext context) {
    print("data ${md.markdownToHtml(_markdownData)}");
    return Material(
      child: Scaffold(
        appBar: AppBar(
          title: Text(widget.article.title),
          elevation: 0.0,
          bottom: new PreferredSize(
            preferredSize: const Size.fromHeight(1.0),
            child: isLoad
                ? new LinearProgressIndicator()
                : new Divider(
                    height: 1.0,
                    color: Theme.of(context).primaryColor,
                  ),
          ),
        ),
       body:  Column(
         children: <Widget>[
           Expanded(
             child: HtmlView(data:_markdownData,),
           ),
           SizedBox(
             height: 48,
             child: Container(
               color: Colors.orange,
             ),
           )
         ],
       ),

      ),
    );
  }
}
